package kr.or.javacafe.magic;

public class MagicFactory {
	public static IMagic imagic;
	
	private static MagicFactory magicFactory;	
	private MagicFactory(){} // MagicFactory magicFactory = new MagicFactory(); X
	public static MagicFactory getInstance(){
		if (magicFactory==null) {
			magicFactory = new MagicFactory();
		}
		return magicFactory;
	}	
	
	public static IMagic factory(int n){
		if (n%2!=0) {
			imagic = new OddMagicSquare(n);
		}else if(n%4==0){
			imagic = new FourMagicSquare(n);
		}else{
			imagic = new SixMagicSquare(n);
		}
		return imagic;
	}	
}
